package com.woniuxy.common;

import lombok.Data;

import java.io.Serializable;

/**
 * Date: 2021/6/28:15:18  <br/>
 * Description:
 */
@Data
public class CommonResult<T> implements Serializable {
    private int code;

    private String message;

    private T data;

    public CommonResult() {
    }

    public CommonResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public CommonResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static CommonResult success(){
        return new CommonResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }
    public static <T> CommonResult success(T data){
        return new CommonResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }
    public static <T> CommonResult success(int code, String message,T data){
        return new CommonResult(code,message,data);
    }

    public static CommonResult fail(){
        return new CommonResult(ResultCode.FAIL.getCode(),ResultCode.FAIL.getMessage());
    }

    public static CommonResult fail(String message){
        return new CommonResult(ResultCode.FAIL.getCode(),message);
    }

    public static CommonResult fail(int code, String message){
        return new CommonResult(code,message);
    }

}
